<?php
namespace Portal\Api\Iadminossms;

use Portal\Common\DataApi as Api;

/**
 * 短信组件
 */
class Supplier extends Api {

    protected function getDataModel() {
        return new \Portal\Model\Sms\Supplier();
    }

    public function getRules() {
        $rules = parent::getRules();

        $rules['createDataKaifain'] = array(
            'newData' => array('name' => 'newData', 'type' => 'array', 'format' => 'json', 'require' => true, 'desc' => \PhalApi\T('post data')),
            //'sms_supplier_name' => array('name' => 'sms_supplier_name', 'require' => true),
            //'AccessKey' => array('name' => 'AccessKey', 'require' => true),
        );

        return $rules;
    }

    /**
     * 开发屋
     */
    public function createDataKaifain() {
        $AccessKey = $this->newData['AccessKey'];
        $this->newData['sms_supplier_config'] = json_encode(array('AccessKey' => $AccessKey));
        unset($this->newData['AccessKey']);

        $this->newData['sms_supplier_type'] = 'kaifain';;
        return $this->createData();
    }

    protected function afterGetData($data) {
        $data['sms_supplier_config'] = json_decode($data['sms_supplier_config'], true);
        return $data;
    }

    protected function beforeUpdateData($updateData) {
        return $updateData;
    }

    protected function beforeCreateData($newData) {
        $newData['add_time'] = date('Y-m-d H:i:s');
        return $newData;
    }
}



